 
/*根据主表查询明细*/
efgrid_onRowClicked = function( grid_id, row_index ){ 
	if(grid_id == "ef_grid_result"){ 
		var grid = efgrid.getGridObject(grid_id); 
		var selectedRow=grid.getRowData(row_index);
		for(var item in selectedRow){
			var colname=item;
			var colvalue=selectedRow[item];
			$('#ef_region_mainadd').find('#result_add-0-'+colname).val(colvalue);
		} 
		
	}
}


var ajax_callback = {
		onSuccess : function(eiInfo) {
			var grid = efgrid.getGridObject("ef_grid_result");
			grid.refresh(eiInfo);
		}, 
		onFail:function(eMsg)
		{
			alert("确认失败，原因："+eMsg);
		}

}	

button_insert_onclick = function (){
	check();
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('result_add').getRows(0)[0][9].trim()==""){
		EFAlert("下井检查情况不能为空");
		return;
	}
	
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info) {
		EiCommunicator.send("ZMCK20", "insert", info, ajax_callback);
	}
}

button_update_onclick = function (){
	check();
	
	var status=$('#result_add-0-fdStatus').val();
	
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info && status != "上报") {
		EiCommunicator.send("ZMCK20", "update", info, ajax_callback);
	}else{
		EFAlert("只能对草拟的记录进行修改！"); return;
	} 
}


button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCK20","query");
}

button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCK20","delete",true);
	}); 
}
button_generate_onclick = function (){
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCK20","generate",true);
}

button_report_onclick = function (){
	if (isSelected("ef_grid_result") == 0)
		return; 
	efgrid.submitForm( "ef_grid_result", "ZM","ZMCK20","report",true);
}

//非空校验，日期校验
check = function()
{
	var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日 
    var clock = year + "-";
    if(month < 10) clock += "0";
    clock += month + "-";
    if(day < 10) clock += "0";
    clock += day + " "; 
    var date = clock;
    
    var fdLocationTime = ($('#result_add-0-fdLocationTime').val()).substr(0,10);//下井时间
    var fdVirtualDate = $('#result_add-0-fdVirtualDate').val();//调度日期
    var fdCurrentDate = $('#result_add-0-fdCurrentDate').val();//当前日期
    if(fdLocationTime > fdVirtualDate){
    	alert("下井时间不能晚于调度日期");return;
    }
    if(date < fdVirtualDate){
    	alert("调度日期不能晚于当前日期"+date);return;
    }
    
	
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('result_add').getRows(0)[0][7].trim()==""){
		EFAlert("班次不能为空");
		return;
	}	
	if(ei_info.getBlock('result_add').getRows(0)[0][2].trim()==""){
		EFAlert("汇报人不能为空");
		return;
	}	
	if(ei_info.getBlock('result_add').getRows(0)[0][0].trim()==""){
		EFAlert("汇报部门不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][3].trim()==""){
		EFAlert("下井时间不能为空");
		return;
	}	
	if(ei_info.getBlock('result_add').getRows(0)[0][4].trim()==""){
		EFAlert("调度时间不能为空");
		return;
	}	
//	if(ei_info.getBlock('result_add').getRows(0)[0][5].trim()==""){
//		EFAlert("当前日期不能为空");
//		return;
//	}	
	if(ei_info.getBlock('result_add').getRows(0)[0][9].trim()==""){
		EFAlert("下井检查情况不能为空");
		return;
	}	
}






